package com.project.config.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;

import java.io.IOException;

@Slf4j
public class CustomResponseErrorHandler extends DefaultResponseErrorHandler {

    @Override
    public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
        return super.hasError(clientHttpResponse);
    }

    @Override
    public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
        HttpStatus statusCode = clientHttpResponse.getStatusCode();
        if (statusCode.isError()) {
            log.error("Http Response : 本次请求失败! {} {} {}",
                    statusCode.value(), statusCode.getReasonPhrase(), clientHttpResponse.getStatusText());
            return;
        }
        super.handleError(clientHttpResponse);
    }

}
